package vek.XML.Parsers;

import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import vek.XML.parsedObjects.ParsedObjectInterface;
import vek.XML.parsedObjects.ParsedRestaurant;


/**
 * Parses Restaurant XML files.
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class XMLParserRestaurants extends XMLParserComercial implements NonAbstractXMLParserInterface {
    
    //parsing variables
    protected boolean parsingRestaurant;
   
    private ArrayList<String> typesOfFoodSold = new ArrayList<String>();
    
    private ArrayList<ParsedObjectInterface> restaurants = new ArrayList<ParsedObjectInterface>();


    @Override
    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
        
        super.startElement(uri, localName, qName, atts);
        
        if(localName.equals("restaurant"))
            {
                typesOfFoodSold = new ArrayList<String>();
                parsingRestaurant = true;
            }
        if(parsingRestaurant)
            {
                setTopElementStartTagsRestaurant(uri, localName, qName, atts);
            }
        
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {   
        
        super.endElement(uri, localName, qName);
        if(localName.equals("restaurant"))
            {
                ParsedRestaurant res = new ParsedRestaurant(parsedComercial, typesOfFoodSold);
                restaurants.add(res);
                returnedParsedObjects.add(res);
                typesOfFoodSold = new ArrayList<String>();
            }
        if(parsingRestaurant)
            {
                setTopElementEndTagsRestaurant(uri, localName, qName);
                
                if(localName.equals("foodtype"))
                {
                    typesOfFoodSold.add(tempElementData);
                }
            }
        
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        
       tempElementData = new String(ch, start, length);
        
    }
    
    private void setTopElementEndTagsRestaurant(String uri, String localName, String qName) throws SAXException 
    {       
       
    }
    
    private void setTopElementStartTagsRestaurant(String uri, String localName, String qName, Attributes atts) throws SAXException
    {
          
    }

    public ArrayList<ParsedObjectInterface> getParsedObjects() {
        return restaurants;
    }

}
